package jpaperwork.meta.transformer;

import jpaperwork.meta.transformer.path.Path;
import jpaperwork.meta.descriptor.*;

import java.util.List;

import org.hypirinha.html.elements.contents.DivContent;
import org.hypirinha.html.elements.Div;
import org.hypirinha.html.elements.Input;
import static org.hypirinha.html.ElementFactory.*;
import static org.hypirinha.html.AttributeFactory.*;
/**
 * User: fleipold
 * Date: Sep 28, 2009
 * Time: 10:42:53 AM
 */
public class HtmlBuilder implements FormBuilder {

   
    public Object buildFlat(Path path, Flat flat, Object transformee) {
        Input input = input(type("text"), value(transformee.toString()), name(path.toHtmlName()));
        return input;
    }

    public Object buildForm(Path path, Form form, List<FieldValue> transformedFields) {
        Div div = div();
        for (FieldValue fieldValue : transformedFields){
            div.div()
                .contains(
                    label().text(fieldValue.getField().getName()),
                    (DivContent) fieldValue.getValue()
                );
        }

        return div;
    }

    public Object buildCollection(Path path, Aggregation aggregation, List transformedValues) {
        Div div = div();
        for (Object transformedValue : transformedValues){
            div.contains((DivContent) transformedValue);
        }
        return div;
    }

    public Object buildPolymorhpic(Path path, Polymorphism polymorphism, DiscriminatedType actualType, Object transformedValue) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
